package com.arrake.utils;

import org.dom4j.Document;

import java.util.List;

public class BusinessModel {
    public static void clearModel(String filePath) throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];

        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);

        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }

    public static void chineseModel01(String filePath)throws Exception {
//        Document[] documents = DocxReader.readerXmlDocRes(filePath);
//        Document docXml = documents[0];
//        Document resXml = documents[1];
//
//        NormalOperation.globalFormatXml(docXml,filePath);
//        String docxText = FormatToReplace.xmlToText(docXml);
//        //业务逻辑
//        docxText = NormalOperation.globalFormatText(docxText);
////        题型分类
//        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)",docxText);
//        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
//        bigBlockList.set(0, title);
//        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
//        bigBlockList.set(1, singleChooseText);
//        String multipleText = NormalOperation.multipleChooseChinese(bigBlockList.get(2));
//        bigBlockList.set(2, multipleText);
//        String translationText = NormalOperation.singleLineChinese(bigBlockList.get(3), pre01);
//        bigBlockList.set(3, translationText);
//        String writeFromMemory = NormalOperation.singleLineChinese(bigBlockList.get(4), pre01);
//        bigBlockList.set(4, writeFromMemory);
//        String readText = NormalOperation.readChinese(bigBlockList.get(5), pre04, pre04_c);
//        bigBlockList.set(5, readText);
//        String writeChinese = NormalOperation.writeChinese(bigBlockList.get(6));
//        bigBlockList.set(6, writeChinese);
//        docxText = "";
//        for (String s : bigBlockList) {
//            docxText = docxText + s;
//        }
//        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }

    public static void chineseModel02(String filePath) throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];
//
        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);
//        题型分类
        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)[\\s\\S]*?\\d{1,2}\\.",docxText);
        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
        bigBlockList.set(0, title);
        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
        bigBlockList.set(1, singleChooseText);
        String pre01 = "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.30&gt;古文翻译题（将下列各题中加横线的字词/句子译成现代汉语）\n\n";
        String translationText = NormalOperation.singleLineChinese(bigBlockList.get(2), pre01);
        bigBlockList.set(2, translationText);
        String pre02 = "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.31>名句默写题\n\n";
        String writeFromMemory = NormalOperation.singleLineChinese(bigBlockList.get(3), pre02);
        bigBlockList.set(3, writeFromMemory);
        String pre04 = "&lt;block&gt;\n" +
                "&lt;TYPE.MATERIAL.32>阅读题\n" +
                "&lt;材料&gt;";
        String pre04_c = "&lt;TYPE.SUBJECT.32&gt;\n\n";
        String readText = NormalOperation.readChinese(bigBlockList.get(4), pre04, pre04_c);
        bigBlockList.set(4, readText);
        String writeChinese = NormalOperation.writeChinese(bigBlockList.get(5));
        bigBlockList.set(5, writeChinese);
        docxText = "";
        for (String s : bigBlockList) {
            docxText = docxText + s;
        }
        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
    public static void englishModel01(String filePath)throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];

        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);
        List<String> bigBlockList = NormalOperation.division("(Part[\\s\\S]*?)Direction",docxText);
        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
        bigBlockList.set(0, title);
        String singleChooseText = NormalOperation.singleChooseEnglish(bigBlockList.get(1));
        bigBlockList.set(1, singleChooseText);
        String readingText = NormalOperation.readingEnglish(bigBlockList.get(2));
        bigBlockList.set(2, readingText);
        String clozeText = NormalOperation.clozeEnglilsh(bigBlockList.get(3));
        bigBlockList.set(3, clozeText);
        String writeText = NormalOperation.writeEnglish(bigBlockList.get(4));
        bigBlockList.set(4, writeText);
        docxText = "";
        for (String s : bigBlockList) {
            docxText = docxText + s;
        }
        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
    public static void politicalModel01(String filePath)throws Exception {
//        Document[] documents = DocxReader.readerXmlDocRes(filePath);
//        Document docXml = documents[0];
//        Document resXml = documents[1];
//
//        NormalOperation.globalFormatXml(docXml,filePath);
//        String docxText = FormatToReplace.xmlToText(docXml);
//        //业务逻辑
//        docxText = NormalOperation.globalFormatText(docxText);
//
//        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)\\d{1,2}\\.",docxText);
//        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
//        bigBlockList.set(0, title);
//        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
//        bigBlockList.set(1, singleChooseText);
//        String multipleText = NormalOperation.singleLineChinese(bigBlockList.get(2), pre01);
//        bigBlockList.set(2, multipleText);
//        String writeFromMemory01 = NormalOperation.singleLineChinese(bigBlockList.get(3), pre01);
//        bigBlockList.set(3, writeFromMemory01);
//        String writeFromMemory02 = NormalOperation.singleLineChinese(bigBlockList.get(4), pre01);
//        bigBlockList.set(4, writeFromMemory02);
//        String writeFromMemory03 = NormalOperation.singleLineChinese(bigBlockList.get(5), pre01);
//        bigBlockList.set(5, writeFromMemory03);
//        String s1 = NormalOperation.readChinese(bigBlockList.get(6), pre04, pre04_c);
//        bigBlockList.set(6, s1);
//
//        docxText = "";
//        for (String s : bigBlockList) {
//            docxText = docxText + s;
//        }
//
//        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
    public static void politicalModel02(String filePath)throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];

        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);

        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)\\d{1,2}\\.",docxText);
        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
        bigBlockList.set(0, title);
        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
        bigBlockList.set(1, singleChooseText);
        String multipleText = NormalOperation.multipleChooseChinese(bigBlockList.get(2));
        bigBlockList.set(2, multipleText);
        String pre01 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.13&gt;辨析题\n\n";
        String writeFromMemory01 = NormalOperation.singleLineChinese(bigBlockList.get(3),pre01);
        bigBlockList.set(3, writeFromMemory01);
        String pre02 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.126&gt;问答题\n\n";
        String writeFromMemory02 = NormalOperation.singleLineChinese(bigBlockList.get(4), pre02);
        bigBlockList.set(4, writeFromMemory02);
        String pre03 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.12&gt;论述题\n\n";
        String writeFromMemory03 = NormalOperation.singleLineChinese(bigBlockList.get(5), pre03);
        bigBlockList.set(5, writeFromMemory03);
        String pre04 = "&lt;block&gt;\n" +
                "&lt;TYPE.MATERIAL.160&gt;案例分析题\n" +
                "&lt;材料&gt;";
        String pre04_c = "\n&lt;TYPE.SUBJECT.160&gt;\n\n";
        String s1 = NormalOperation.readChinese(bigBlockList.get(6), pre04, pre04_c);
        bigBlockList.set(6, s1);

        docxText = "";
        for (String s : bigBlockList) {
            docxText = docxText + s;
        }

        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
    public static void mathModel01(String filePath)throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];

        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);

        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)\\d{1,2}\\.",docxText);
        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
        bigBlockList.set(0, title);
        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
        bigBlockList.set(1, singleChooseText);
        String pre02 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.28&gt;填空题\n\n";
        String multipleText = NormalOperation.singleLineChinese(bigBlockList.get(2), pre02);
        bigBlockList.set(2, multipleText);
        String pre03 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.26&gt;计算题\n\n";
        String writeFromMemory01 = NormalOperation.singleLineChinese(bigBlockList.get(3), pre03);
        bigBlockList.set(3, writeFromMemory01);
        String writeFromMemory02 = NormalOperation.singleLineChinesePlus(bigBlockList.get(4));
        bigBlockList.set(4, writeFromMemory02);


        docxText = "";
        for (String s : bigBlockList) {
            docxText = docxText + s;
        }

        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
    public static void managementModel01(String filePath)throws Exception {
        Document[] documents = DocxReader.readerXmlDocRes(filePath);
        Document docXml = documents[0];
        Document resXml = documents[1];

        NormalOperation.globalFormatXml(docXml,filePath);
        String docxText = FormatToReplace.xmlToText(docXml);
        //业务逻辑
        docxText = NormalOperation.globalFormatText(docxText);

        List<String> bigBlockList = NormalOperation.division("\\n([一二三四五六]、.*?.*\\n)\\d{1,2}\\.",docxText);
        String title = NormalOperation.getTitle(bigBlockList.get(0),"100","120");
        bigBlockList.set(0, title);
        String singleChooseText = NormalOperation.singleChooseChinese(bigBlockList.get(1));
        bigBlockList.set(1, singleChooseText);
        String multipleText = NormalOperation.multipleChooseChinese(bigBlockList.get(2));
        bigBlockList.set(2, multipleText);
        String pre01 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.18&gt;名词解释\n\n";
        String writeFromMemory01 = NormalOperation.singleLineChinese(bigBlockList.get(3), pre01);
        bigBlockList.set(3, writeFromMemory01);
        String pre02 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.4&gt;简答题\n\n";
        String writeFromMemory02 = NormalOperation.singleLineChinese(bigBlockList.get(4), pre02);
        bigBlockList.set(4, writeFromMemory02);
        String pre03 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.SUBJECT.12&gt;论述题\n\n";
        String writeFromMemory03 = NormalOperation.singleLineChinese(bigBlockList.get(5), pre03);
        bigBlockList.set(5, writeFromMemory03);
        String pre04 = "\n" +
                "&lt;block&gt;\n" +
                "&lt;TYPE.MATERIAL.160&gt;案例分析题\n" +
                "&lt;材料&gt;";
        String pre04_c = "\n&lt;TYPE.SUBJECT.160&gt;\n\n";
        String readText = NormalOperation.readChinese(bigBlockList.get(6),pre04,pre04_c);
        bigBlockList.set(6, readText);

        docxText = "";
        for (String s : bigBlockList) {
            docxText = docxText + s;
        }

        FormatToReplace.textToDocx(docxText,resXml,filePath);
    }
}
